// pages/user/user.js
const orderService = require('../../service/orderService.js')
const utils = require('../../utils/util.js');
// load promise 
require('../../utils/wx-pro.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userImg: '',
    userName: '',
    NoPaycount: 0,
    PtCount: 0,
    DeliveredCount: 0,
    showToast: false,
    toastMsg: ''
  },

  //错误提示
  showToastFuc(msg) {
    this.setData({
      showToast: true,
      toastMsg: msg
    })
    setTimeout(() => {
      this.setData({
        showToast: false,
        toastMsg: ''
      })
    }, 2000)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getUserHomeInfo()
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (wx.getStorageSync('userInfo')){
      var data = JSON.parse(wx.getStorageSync('userInfo'))
      this.setData({
        userImg: data.thirdPartLogin.headImageUrl,
        userName: data.thirdPartLogin.nickName
      })
    }
  },
  getUserHomeInfo(){
    orderService.getOrderCount().then(data => {
      if (data.code == 200) {
        console.log(data.response)
        this.setData({
          userImg: data.response.CustomerImg,
          userName: data.response.Username,
          NoPaycount: data.response.NoPaycount,
          PtCount: data.response.PtCount,
          DeliveredCount: data.response.DeliveredCount
        })
      } else {
        this.showToastFuc(data.message)
      }
    })
      .catch(() => {
        console.log('error')
      })
  },
  callPhone(){
    wx.makePhoneCall({
      phoneNumber: '02566048533' 
    })
  }
})